package com.wang.API;

import com.wang.bean.Lesson;
import com.wang.bean.Result;
import com.wang.service.LessonService;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("api")
public class LessonController {

    @Autowired
    private LessonService lessonService;

    /**
     * 查询所有课程接口
     * @return
     */
    @RequestMapping(value = "/lessonlistall")
    @RequiresPermissions("sys:task:lessonlistall")
    public Result lessonlistall(){
        List<Lesson> lessonlistall = lessonService.lessonlistall();
        Result result = new Result();
        result.setCode("701");
        result.setData(lessonlistall);
        return result;
    }

    /*
    @ApiParam(name = "lesson_id", value = "课程ID",required = true) @RequestParam(value = "lesson_id", required = true) String lesson_id,
            @ApiParam(name = "lesson_code", value = "课程代码",required = true) @RequestParam(value = "lesson_code", required = true) String lesson_code,
            @ApiParam(name = "lesson", value = "课程名称",required = true) @RequestParam(value = "lesson", required = true) String lesson,
            @ApiParam(name = "info", value = "课程说明",required = false) @RequestParam(value = "info", required = false) String info,
            @ApiParam(name = "remark", value = "课程其他备注信息",required = false) @RequestParam(value = "remark", required = false) String remark,
            @ApiParam(name = "is_del", value = "课程是否删除/是否可用",required = false) @RequestParam(value = "is_del", required = false) String is_del
     */

    /**
     *
     * @param le
     * @return
     */
    @RequestMapping(value = "/lessonadd")
    @RequiresPermissions("sys:task:lessonadd")
    public Result lessonadd(@RequestBody Lesson le){
        Result result = new Result();
        if (le.getLesson_id()==null){
            result.setCode("702");
            return result;
        }
        if (lessonService.lessonsearch(le.getLesson_id()) != null){
            result.setCode("710");
            return result;
        }
        if (le.getLesson_code()==null){
            result.setCode("703");
            return result;
        }
        if (le.getLesson()==null){
            result.setCode("704");
            return result;
        }
        lessonService.lessonadd(le);
        result.setCode("705");
        return result;
    }

    /**
     *
     * @param lesson_id
     * @return
     */
    @RequestMapping(value = "/lessondel")
    @RequiresPermissions("sys:task:lessondel")
    public Result lessondel(@RequestBody String lesson_id){
        Result result = new Result();
        Lesson lesson = new Lesson();
        lesson.setLesson_id(lesson_id);
        if (lessonService.lessonsearch(lesson.getLesson_id()) == null){
            result.setCode("707");
            return result;
        }
        lessonService.lessondel(lesson);
        result.setCode("706");
        return result;
    }

    /**
     *
     * @param le
     * @return
     */
    @RequestMapping(value = "/lessondit")
    @RequiresPermissions("sys:task:lessondit")
    public Result lessondit(@RequestBody Lesson le){
        Result result = new Result();
        if (lessonService.lessonsearch(le.getLesson_id()) == null){
            result.setCode("707");
            return result;
        }
        lessonService.lessondit(le);
        result.setCode("708");
        return result;
    }

    /**
     *
     * @param getLesson_id
     * @return
     */
    @RequestMapping("/lessonsearch")
    @RequiresPermissions("sys:task:lessonsearch")
    public Result lessonsearch(@RequestBody String getLesson_id){
        Result result = new Result();
        Lesson lesson = lessonService.lessonsearch(getLesson_id);
        result.setCode("709");
        result.setData(lesson);
        return result;
    }
}

